package com.wwj.my_ummary;

import com.fasterxml.jackson.databind.SerializationFeature;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

/**
 * EnableAspectJAutoProxy 启用切面自动代理
 * MapperScan 扫描Dao层
 *
 */
@EnableScheduling
@MapperScan({"com.wwj.my_ummary.**.mapper"})
@SpringBootApplication
public class MyMmaryApplication extends SpringBootServletInitializer {


	@Resource
	private KafkaTemplate kafkaTemplate;

	public static void main(String[] args) {
		SpringApplication.run(MyMmaryApplication.class, args);
	}


	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(MyMmaryApplication.class);
	}



	@Bean
	public Jackson2ObjectMapperBuilderCustomizer customizer(){
		return builder -> builder.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
	}


//	@Scheduled(cron = "0/1 * * * * ?")
//	public void send(){
//
//		SecureRandom random = new SecureRandom();
//
//		String[] message=new String[]{"this is a demo","hello world","hello boy"};
//		ListenableFuture future = kafkaTemplate.send("topica", message[random.nextInt(message.length)]);
//		future.addCallback(o -> System.out.println("send-消息发送成功：" + message), throwable -> System.out.println("消息发送失败：" + message));
//	}

//	@KafkaListener(topics = "topica",id="g1")
//	public void processMessage(ConsumerRecord<?, ?> record) {
//		System.out.println("record:"+record);
//	}


}
